package borge.web.teamspirit.client.data;

import java.util.Date;

import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import borge.web.teamspirit.client.TeamSpirit;
import borge.web.teamspirit.client.interfaces.PersistentData;
import borge.web.teamspirit.client.interfaces.UserContentProvider;

/**
 * Database object.
 * Representation of a news item.
 * @author Andreas Borglin
 *
 */
@SuppressWarnings("serial")
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable="true")
public class News implements PersistentData {

	/* Encoded key generated by GAE when first saved.
	 * Guaranteed to be unique and contains mapping to 
	 * a team using gae.pk-name key defined below. */
	@PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    @Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
    private String iEncodedKey;
    
	// Parent can be any entity
    @Persistent
    private String iParentKey;
    
    @Persistent
    private String iPosterName;
    
    @Persistent
	private String iTitle;
	
    @Persistent
	private String iPersonKey;
	
    @Persistent
	private Date iDate;
	
    @Persistent
	private String iText;
    
    public static News createNewsFromUserForm(UserContentProvider aProvider){
        
        News news = new News();
        news.setTitle(aProvider.getString(TeamSpirit.getConstants().title()));
        news.setDate(aProvider.getDate(TeamSpirit.getConstants().date()));
        news.setText(aProvider.getString(TeamSpirit.getConstants().text()));
        
        // Poster has to be set elsewhere..
        
        return null;
    }
	
	public News(){
	    
	}
	
	/*public Long getNewsId(){
	    return iNewsId;
	}
	
	public void setNewsId(Long aNewsId){
	    iNewsId = aNewsId;
	}*/
	
	public String getEncodedKey(){
		return iEncodedKey;
	}
	
	public void setParentKey(String aKey){
		iParentKey = aKey;
	}
	
	public String getParentKey(){
		return iParentKey;
	}

	public void setPosterName(String aName){
		iPosterName = aName;
	}
	
	public String getPosterName(){
		return iPosterName;
	}
	
    public String getTitle(){
	        return iTitle;
	    }

    public void setTitle(String aTitle) {
        iTitle = aTitle;
    }
    
    public String getPersonKey(){
        return iPersonKey;
    }
    
    public void setPersonKey(String aKey){
        iPersonKey = aKey;
    }
    
    public Date getDate(){
        return iDate;
    }
    
    public void setDate(Date aDate){
        iDate = aDate;
    }
    
    public String getText(){
        return iText;
    }
    
    public void setText(String aText){
        iText = aText;
    }
    
    public String dumpContent(){
        return new String("Dump" +
                "\nId:" + iEncodedKey +
                "\nTitle:" + iTitle +
                "\nPoster:" + iPersonKey +
                "\nDate:" + iDate +
                "\nText:" + iText);
    }

	@Override
	public String getDisplayingWidget() {
		// TODO Auto-generated method stub
		return null;
	}
	

}
